package com.jz.community.moduleshopping.goodsDetail.presenter;

import com.jz.community.basecomm.bean.baseGoods.BaseGoodsInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.moduleshopping.goodsDetail.bean.GoodsDetailInfo;
import com.jz.community.moduleshopping.goodsDetail.model.GoodsDetailModel;
import com.jz.community.moduleshopping.goodsDetail.model.GoodsDetailModelImpl;
import com.jz.community.moduleshopping.goodsDetail.ui.GoodsDetailView;

/**
 * Created by Tony.Fan on 2018/3/27 09:56
 */
public class GoodsDetailPresenter extends BaseLifeCyclePresent<GoodsDetailView.View> implements GoodsDetailView.Presenter {

    private GoodsDetailView.View goodsDetailView;
    private GoodsDetailModel goodsDetailModel;

    public GoodsDetailPresenter(GoodsDetailView.View view) {
        goodsDetailView = view;
        goodsDetailModel = new GoodsDetailModelImpl(view.getContext());
    }

    @Override
    public void getGoodsDetailInfo(String url) {

        goodsDetailModel.requestGoodsDetailInfo(url, new OnLoadListener<GoodsDetailInfo>() {
            @Override
            public void onSuccess(GoodsDetailInfo goodsDetailInfo) {
                if (Preconditions.isNullOrEmpty(goodsDetailInfo)) {
                    return;
                }
                goodsDetailView.showGoodsDetailInfo(goodsDetailInfo);
            }

            @Override
            public void onFail(String s,int code) {

            }
        });
    }

    @Override
    public void getShopGoodsInfo(String page, String shopid) {
        goodsDetailModel.requestDetailShopInfo(page, shopid, new OnLoadListener<BaseGoodsInfo>() {
            @Override
            public void onSuccess(BaseGoodsInfo shopGoodsInfo) {
                goodsDetailView.showDetailShopInfo(shopGoodsInfo);
            }

            @Override
            public void onFail(String s,int code) {

            }
        });
    }


    @Override
    public void setPresenter(GoodsDetailView.View v) {
        super.setPresenter(v);
    }
}
